package com.acme.bankapp.service.bank;

import static org.junit.Assert.*;

import org.junit.Test;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.domain.bank.SavingAccount;
import com.acme.bankapp.domain.bank.exceptions.ClientExistsException;
import com.acme.bankapp.domain.bank.exceptions.NotEnoughFundsException;

import static com.acme.bankapp.service.bank.BankReport.*;

public class BankReportTest {

	@Test
	public void test() throws NotEnoughFundsException {
		Bank testBank = new Bank();
		
		try {
			testBank.addClient(new Client(Gender.FEMALE, "Ivanova", new CheckingAccount(1.0, 30)));
			testBank.addClient(new Client(Gender.MALE, "Ivanov",
					new SavingAccount(35)));
		} catch (ClientExistsException e) {
			e.printStackTrace();
		}
		for (Client cli: testBank.getClients()) {
			for (Account acc: cli.getAccounts()) {
				acc.withdraw(30);
			}
		}
		assertEquals(2, getNbOfCustomers(testBank));
		assertEquals(2, getNbOfAccounts(testBank));
		assertEquals(29.0, getBankCredit(testBank), 0.001);
		Double min = Double.NEGATIVE_INFINITY;
		for (Account account : getAccountsSortedBySum(testBank)) {
			assertTrue(min <= account.getBalance());
			min = account.getBalance();
		}
		
	}
}